<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;">
    <input type="hidden" name="tid" th:value="${tid}">
    <div th:if="${cts}">
        <label class="layui-form-label">处理内容</label>
        <div class="layui-input-block">
            <input type="text" id="cContent" class="layui-input"
                   lay-verify="required" name="cContent"  th:value="${cts.cContent}">
        </div>
        <input type="hidden" name="cid" th:value="${cts.cid}">
    </div>
    <div th:if="!${cts}">
        <label class="layui-form-label">处理内容</label>
        <div class="layui-input-block">
            <input type="text" id="cContent" class="layui-input"
                   lay-verify="required" name="cContent">
        </div>
    </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <div  th:if="${cts}">
                    <button class="layui-btn" id="updCts" lay-submit="" lay-filter="updCts">立即修改</button>
                    <button class="layui-btn" id="dltCts" lay-submit="" lay-filter="dltCts">立即删除</button>
                </div>
                <button class="layui-btn" id="editTs" lay-submit="" lay-filter="editTs" th:if="!${cts}">立即保存</button>
            </div>
        </div>
</form>



<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['form','laydate','layer','jquery'],function () {
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.jquery;
        //保存
        form.on('submit(editTs)',function (data) {
            $.ajax({
                url:'/ts/saveCts',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('处理完成',{icon:1},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })
        form.on('submit(updCts)',function (data) {
            $.ajax({
                url:'/ts/updCts',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('处理完成',{icon:1},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })
        form.on('submit(dltCts)',function (data) {
            alert(data.field.cid);
            $.ajax({
                url:'/ts/dltCts/'+data.field.cid,
                type:'get',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('处理完成',{icon:1},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })

    })
</script>
</body>
</html>